﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.Sockets;
using System.Net;
using System.Web.Script.Serialization;

namespace SocketChat.Core.Sockets
{
    /// <summary>
    /// 一个客户端
    /// </summary>
    [Serializable]
    public class Client
    {
        public Guid Id { get; set; }
        public string IP { get; set; }
        public int Port { get; set; }
        public DateTime HeartBeatTime { get; set; }
        public string Name { get; set; }
        public string DisplayName {
            get {
                return string.Format("{0}({1}:{2})", Name, IP, Port.ToString());
            }
        }
        public override string ToString() {
            JavaScriptSerializer jss = new JavaScriptSerializer();
            return jss.Serialize(new { Id = Id, Ip = IP, Port = Port, HeartBeatTime = HeartBeatTime, Name = Name });
        }
        public static Client Prase(string input) {
            JavaScriptSerializer jss = new JavaScriptSerializer();
            return jss.Deserialize<Client>(input);
        }
    }
}
 